﻿using System;
using UnityEditor;
using UnityEngine;

namespace XMLib.AM
{
    public class SyncAnimationPreviewView : IView
    {
        public override string title => "动画同步预览设置";
        public override void OnUpdate()
        {
            
        }
        public override bool useAre => true;

        private Vector2 scrollView = Vector2.zero;


        protected override void OnGUI(Rect contentRect)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            GUILayout.Label("动画同步物体");
            for(int i=0;i< win.syncAnimationObjcts.Count;i++)
            {
                win.syncAnimationObjcts[i] = (GameObject)EditorGUILayout.ObjectField(win.syncAnimationObjcts[i], typeof(GameObject), true);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();
            GUILayout.Label("物体动画");
            for (int i = 0; i < win.syncAnimationNames.Count; i++)
            {
                win.syncAnimationNames[i] = EditorGUILayout.TextField(win.syncAnimationNames[i]); ;
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();
            GUILayout.Label("物体根骨");
            for (int i = 0; i < win.syncAnimationObjctsRootBones.Count; i++)
            {
                win.syncAnimationObjctsRootBones[i] = (Transform)EditorGUILayout.ObjectField(win.syncAnimationObjctsRootBones[i], typeof(Transform), true);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("增加"))
            {
                win.syncAnimationObjcts.Add(null);
                win.syncAnimationObjctsRootBones.Add(null);
                win.syncAnimationNames.Add("");
            }
            if (GUILayout.Button("删除"))
            {
                if (win.syncAnimationObjcts.Count > 0)
                {
                    win.syncAnimationObjcts.RemoveAt(win.syncAnimationObjcts.Count - 1);
                    win.syncAnimationNames.RemoveAt(win.syncAnimationNames.Count - 1);
                    win.syncAnimationObjctsRootBones.RemoveAt(win.syncAnimationObjctsRootBones.Count-1);
                }
            }
        }
    }
}

